package binaryseach;

import java.util.Arrays;

public class BinarySearch2 {
	public static void main(String[] args) {
		int[]arr={1,24,35,75,27,17,10,18,43,20,31};
		Arrays.sort(arr);
		for (int i : arr) {
			System.out.printf("%-3d",i);
		}
		System.out.println();
		int n=75;
		int m=findNum(arr,n);
		if(n!=0)
			System.out.println(n+" is at "+m);
		else
			System.out.println("the num is not exited in the array in fact");
		
	}
    static int findNum(int[]arr,int num){
    	
    	int sind=0;
    	int eind=arr.length-1;
    	while(sind<=eind){
    		int mind=(sind+eind)/2;
    		if(num>arr[mind])
    			sind=mind+1;
    		else if(num<arr[mind])
    			eind=mind-1;
    		else
    			return mind;
    	}
    	return -1;
    }
}
